Pie Chart

Course- R Programming >

Pie chart is drawn using the pie() function in R programming language. This function takes in a vector of non-negative numbers. Let us consider the following data which contains the monthly expenditure breakdown of an individual.

> expenditure
     Housing          Food        Cloths Entertainment         Other 
         600           300           150           100           200

Now let us draw a simple pie chart out of this data using the pie() function.

pie(expenditure)
R Programming Pie Chart

We can see above that a pie chart was plotted with 5 slices. The chart was drawn in anti-clockwise direction using pastel colors.

 

 
 

We can pass in additional parameters to affect the way pie chart is drawn. You can read about it in the help section ?pie. Some of the frequently used ones are, labels-to give names to slices, main-to add a title, col-to define colors for the slices and border-to color the borders. We can also pass the argument clockwise=TRUE to draw the chart in clockwise fashion.

pie(expenditure,
 labels=as.character(expenditure),
 main="Monthly Expenditure Breakdown",
 col=c("red","orange","yellow","blue","green"),
 border="brown",
 clockwise=TRUE
)
R Programming Pie Chart

As seen in the above figure, we have used the actual amount as labels. Also, the chart is drawn in clockwise fashion.

Since the human eye is relatively bad at judging angles, other types of charts are appropriate than pie charts. This is also stated in the R documentation-Pie charts are a very bad way of displaying information. The eye is good at judging linear measures and bad at judging relative areas. A bar chart or dot chart is a preferable way of displaying this type of data.